/***********************************************************************
	filename: 	DaterSystem.h
	created:	16/04/2012
	author:		4Ys

	purpose:	Defines interface for main Dater system class
*************************************************************************/
#ifndef _DaterSystem_h_
#define _DaterSystem_h

#include "DaterCalendarData.h"
#include "DaterSingleton.h"
#include "DaterClientSocket.h"

#include <process.h>

namespace Dater
{
	/*!
	\brief
		The System class is the Dater class that provides access to all other elements in the Dater business system.

		This object must be created by the client application.
	*/
	class System : public Singleton<System>
	{
	public:
		/*!
		\brief
			Create the System object and return a reference to it.
		*/
		static System& create();

		//! Destroy the System object.
		static void destroy();

		/*!
		\brief
			Return singleton System object

		\return
			Singleton System object
		*/
		static	System&	getSingleton(void);


		/*!
		\brief
			Return pointer to singleton System object

		\return
			Pointer to singleton System object
		*/
		static	System*	getSingletonPtr(void);

		/*!
		\brief 
			Get the data of the calendar of the system
		*/
		CalendarData* getCalendarData() const;

		const char* getDateRegex() const{return _dateRegex;}

		const char* getTimeRegex() const{return _timeRegex;}

		void setServerAddress(std::string serverAddress){_serverAddress = serverAddress;}

		std::string getServerAddress(){return _serverAddress;}

		void startSocketListenThread(Dater::ClientSocket*);
	private:
		// unimplemented constructors / assignment
		System(const System& obj);
		System& operator=(const System& obj);

		/*!
		\brief
			Construct a new System object
		*/
		System();

		/*!
		\brief
			Destructor for System objects.
		*/
		~System(void);

		//! adds factories for all the basic event types
		void addStandardEventFactories();

	    //! create the other core system singleton objects (except the logger)
		void createSingletons();

		//! cleanup the core system singleton objects
		void destroySingletons();

		CalendarData* _calendarData;

		const char* _dateRegex;

		const char* _timeRegex;

		std::string _serverAddress;

		HANDLE _netThread;

		unsigned _threadAddr;

		static unsigned int __stdcall netThreadFunction(void*);
	};

}

#endif